package com.cloud.bssp.jvm;

import java.util.ArrayList;
import java.util.List;

/**
 * @description： OOM测试类
 * @author：weirx
 * @date：2021/4/8 15:33
 * @version：3.0
 */
public class OOMTest {

//    /**
//     * 堆溢出
//     */
//    static class OOMObject {
//    }
//    public static void main(String[] args) {
//
//        List<OOMObject> list = new ArrayList<OOMObject>();
//        while (true) {
//            list.add(new OOMObject());
//        }
//    }

    private int stackLength = 1;
    public void stackLeak() {
        stackLength++;
        stackLeak();
    }
    public static void main(String[] args) throws Throwable {
        OOMTest oom = new OOMTest();
        try {
            oom.stackLeak();
        } catch (Throwable e) {
            System.out.println("stack length:" + oom.stackLength);
            throw e;
        }
    }
}
